using UnityEngine;

public class deadToWater : MonoBehaviour
{
	public bool showSeaLevel;

	public float posYForDeadToWater = -3.5f;

	public float posY = -20f;

	private void Start()
	{
		TypeGame curTypeGame = GameController.instance.curTypeGame;
		if (curTypeGame == TypeGame.race)
		{
			base.enabled = false;
		}
	}

	private void Update()
	{
		if ((!(GameController.instance != null) || GameController.instance.curTypeGame != TypeGame.RocketLeague) && Time.frameCount % 5 == 0 && GameController.instance.myPlayer != null && (settings.offlineMode || GameController.instance.playerScript.photonView.isMine) && !GameController.instance.playerScript.isDead)
		{
			if (GameController.instance.myPlayer.transform.position.y < posYForDeadToWater)
			{
				dead();
			}
			else if (GameController.instance.playerScript.inCar && GameController.instance.carScript != null && GameController.instance.carScript.isDead && GameController.instance.carScript.inWater)
			{
				GameController.instance.StopTimerDeadPlayerInTrasnport();
			}
			else if (GameController.instance.playerScript.inCar && GameController.instance.carScript != null && !GameController.instance.carScript.inWater)
			{
				GameController.instance.carScript.isDead = false;
				GameController.instance.carScript.inWater = false;
				GameController.instance.StopTimerWhenOutOfTheWater();
			}
			TypeGame curTypeGame = GameController.instance.curTypeGame;
			if (curTypeGame != TypeGame.race && curTypeGame != TypeGame.tanks && !GameController.instance.playerScript.inCar && !GameController.instance.playerScript.inHelic && GameController.instance.myPlayer.transform.position.y < posY)
			{
				GameController.instance.playerScript.Kill();
			}
		}
	}

	private void dead()
	{
		if ((settings.offlineMode || GameController.instance.playerScript.photonView.isMine) && (GameController.instance.playerScript.inCar || GameController.instance.playerScript.inHelic) && !GameController.instance.carScript.isDead && (!(GameController.instance.carScript != null) || !(GameController.instance.carScript is TitanBehavior)))
		{
			if (GameController.instance.playerScript.inHelic)
			{
				GameController.instance.playerScript.currentCar.GetComponent<HelicopterBehavior>().StopAnimationPropeler();
			}
			GameController.instance.carScript.isDead = true;
			GameController.instance.carScript.inWater = true;
			GameController.instance.carScript.Disable();
			GameController.instance.carScript.rigidCar.isKinematic = false;
			GameController.instance.carScript.rigidCar.AddForce(0f, 10000f, 0f);
			GameController.instance.StartTimerDeadPlayerInTrasnport(5f);
		}
	}
}
